//
//  AppDelegate.swift
//  SmartMachine
//
//  Created by Sherman's iMac on 2019/11/6.
//  Copyright © 2019 Smart. All rights reserved.
//

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    private var contentWinCtrl : SMBaseWindowViewCtrl!
    private var userConfigCtrl : SMConfigWinCtrl!
    private var platformConfigCtrl : SMConfigWinCtrl!
    private var baseConfigCtrl : SMConfigWinCtrl!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
        
        self.contentWinCtrl = SMBaseWindowViewCtrl.init(window: nil)
        let contentCtrl : SMContentSplitCtrl? = SMContentSplitCtrl()
        self.contentWinCtrl.contentViewController = contentCtrl;  self.contentWinCtrl.window?.setFrame(NSMakeRect(0, 0, 900, 600), display: true)
        self.contentWinCtrl.window?.center()
        self.contentWinCtrl.window?.orderFront(nil)
    }

    public func showUserConfigCtrl() {
        
        if self.userConfigCtrl == nil {
            let userCtrl = FUNC_BORAD("SMUserConfigContentViewCtrl")
            self.userConfigCtrl = SMConfigWinCtrl.init(window: nil, winType: SMWindowType.userWindow)
            self.userConfigCtrl.contentViewController = userCtrl
        }
        self.userConfigCtrl.window?.setFrame(NSMakeRect(0, 0, 450, 250), display: true)
        self.userConfigCtrl.window?.center()
        self.userConfigCtrl.window?.orderFront(nil)
    }
    
    func hideUseConfigCtrl() {
        
        if self.userConfigCtrl == nil {
            return
        }
        self.userConfigCtrl.window?.orderOut(nil)
        self.userConfigCtrl = nil
    }
    
    public func showPlatformConfigCtrl() {
        
        if self.platformConfigCtrl == nil {
            let platCtrl = FUNC_BORAD("SMPlatFormContentViewCtrl")
            self.platformConfigCtrl = SMConfigWinCtrl.init(window: nil, winType: SMWindowType.platFormWindow)
            self.platformConfigCtrl.contentViewController = platCtrl
        }
        self.platformConfigCtrl.window?.setFrame(NSMakeRect(0, 0, 800, 400), display: true)
        self.platformConfigCtrl.window?.center()
        self.platformConfigCtrl.window?.orderFront(nil)
    }
    
    func hidePlatFormConfigCtrl() {
        
        if self.platformConfigCtrl == nil {
            return
        }
        self.platformConfigCtrl.window?.orderOut(nil)
        self.platformConfigCtrl = nil
    }
    
    public func showBaseConfigCtrl() {
        
        if self.baseConfigCtrl == nil {
            let contentCtrl = FUNC_BORAD("SMBasicConfigContentViewCtrl")
            self.baseConfigCtrl = SMConfigWinCtrl.init(window: nil, winType: SMWindowType.basicConfigWindow)
            self.baseConfigCtrl.contentViewController = contentCtrl;
        }
        self.baseConfigCtrl.window?.setFrame(NSMakeRect(0, 0, 450, 200), display: true)
        self.baseConfigCtrl.window?.center()
        self.baseConfigCtrl.window?.orderFront(nil)
    }
    
    func hideBasicConfigCtrl() {
        
        if self.baseConfigCtrl == nil {
            return
        }
        self.baseConfigCtrl.window?.orderOut(nil)
        self.baseConfigCtrl = nil
    }
    
    class func appDelegate() -> AppDelegate? {
        return NSApplication.shared.delegate as? AppDelegate
    }
    
    //menu
    @IBAction func basicConfigAction(_ sender: Any) {
        AppDelegate.appDelegate()?.showBaseConfigCtrl()
    }
    
    @IBAction func platformConfigAction(_ sender: Any) {
        AppDelegate.appDelegate()?.showPlatformConfigCtrl()
    }
    
    @IBAction func userAddAction(_ sender: Any) {
        
        AppDelegate.appDelegate()?.showUserConfigCtrl()
    }
    
    @IBAction func userDeleteAction(_ sender: Any) {
        
    }
    
    @IBAction func workingAction(_ sender: Any) {
        
    }
    
    @IBAction func rebackAction(_ sender: Any) {
        
    }
    
    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }
}

